import grails.util.GrailsUtil
import org.apache.shiro.crypto.hash.Sha256Hash
import org.bjou.*

class BootStrap {

    def init = { servletContext ->
        switch(GrailsUtil.environment){
            case "development":
                 break
                  
            case "production": 
                  
//                def admin = new ShiroUser(username: "admin", passwordHash: new Sha256Hash("admin").toHex()) 
//                admin.save() 
//                
//                def plan = new ShiroUser(username: "plan", passwordHash: new Sha256Hash("plan").toHex()) 
//                plan.save() 
//                
//                def resource = new ShiroUser(username: "resource", passwordHash: new Sha256Hash("resource").toHex()) 
//                resource.save()
//                
//                //注册用户角色
//                def role_regUser = new ShiroRole(name:"注册用户",roleDscp:"注册用户描述",roleType:1)
//                role_regUser.addToPermissions("UserBaseinfo:*")
//                role_regUser.save()
//                
//                //管理员
//                def role_admin = new ShiroRole(name:"管理员",roleDscp:"系统管理员",roleType:1)
//                role_admin.addToUsers(admin)
//                role_admin.addToPermissions("*:*")
//                role_admin.save()
//                
//                //分校
//                def user1 = new ShiroUser(username: "cw", passwordHash: new Sha256Hash("cw").toHex()) 
//                user1.save() 
//                def user2 = new ShiroUser(username: "ft", passwordHash: new Sha256Hash("ft").toHex()) 
//                user2.save()
//                
//                def branch1 = new Branch(branchName:"崇文分校",branchType:"教学单位")
//                branch1.addToUsers(user1)
//                branch1.save()
//                
//                def branch2 = new Branch(branchName:"丰台分校",branchType:"教学单位")
//                branch2.addToUsers(user2)
//                branch2.save()
//                
//                def role_branch = new ShiroRole(name:"分校角色",roleDscp:"分校角色描述",roleType:1)
//                role_branch.addToUsers(user1)
//                role_branch.addToUsers(user2)
//                role_branch.addToPermissions("Course")
//                role_branch.addToPermissions("BranchCourse")
//                role_branch.save()
//                
//                //计划科
//                def role_plan = new ShiroRole(name:"计划科",roleDscp:"计划科角色描述",roleType:1)
//                role_plan.addToUsers(plan)
//                role_plan.addToPermissions("Course")
//                role_plan.addToPermissions("CourseRule")
//                role_plan.save()
//                
//                //资源科
//                def role_resource = new ShiroRole(name:"资源科",roleDscp:"资源科角色描述",roleType:1)
//                role_resource.addToUsers(resource)
//                role_resource.addToPermissions("Course")
//                role_resource.save()
//                
//                
//                
////                //初始化学期
////                def term = new Term(currentTerm:"2012年春季",entryTerm:"2012年春季",courseTerm:1)
////                term.save()
////                term = new Term(currentTerm:"2012年春季",entryTerm:"2011年秋季",courseTerm:2)
////                term.save()
////                term = new Term(currentTerm:"2012年春季",entryTerm:"2011年春季",courseTerm:3)
////                term.save()
////                term = new Term(currentTerm:"2012年春季",entryTerm:"2010年秋季",courseTerm:4)
////                term.save()
////                term = new Term(currentTerm:"2012年春季",entryTerm:"2010年春季",courseTerm:5)
////                term.save()
////                term = new Term(currentTerm:"2012年春季",entryTerm:"2009年秋季",courseTerm:6)
////                term.save()
//                
//            
//                //初始化用户组
//                def userGroup1 = new UserGroup(groupName:"理工教师组")
//                userGroup1.save()
//                def userGroup2 = new UserGroup(groupName:"文法教师组")
//                userGroup2.save()
//                def userGroup = new UserGroup(groupName:"财经教师组")
//                userGroup.save()
//                userGroup = new UserGroup(groupName:"共建教师组")
//                userGroup.save()
//                userGroup = new UserGroup(groupName:"校内兼职教师组")
//                userGroup.save()
//                userGroup = new UserGroup(groupName:"校外兼职教师组")
//                userGroup.save()
//                userGroup = new UserGroup(groupName:"托管专职教师组")
//                userGroup.save()
//                userGroup = new UserGroup(groupName:"校内退休教师组")
//                userGroup.save()
//                
//            
//                //教师1
//                
//                 
//                def teacher1 = new ShiroUser(username: "老师A", passwordHash: new Sha256Hash("1").toHex()) 
//                teacher1.save()
//                def teacher2 = new ShiroUser(username: "老师B", passwordHash: new Sha256Hash("1").toHex()) 
//                teacher2.save()
//                
//                def teacherBaseinfo = new UserBaseinfo()
//               teacherBaseinfo.fullname = "老师A"
//               teacherBaseinfo.setUser(teacher1)
//               teacherBaseinfo.setUserGroup(userGroup1)
//               teacherBaseinfo.save()
//               
//            
//                teacherBaseinfo = new UserBaseinfo()
//               teacherBaseinfo.fullname = "老师B"
//               teacherBaseinfo.setUser(teacher2)
//               teacherBaseinfo.setUserGroup(userGroup2)
//               teacherBaseinfo.save()
//               
//                
//            
//                
//            
//            	
//                
//               
//                //系部用户
//                def department1 = new ShiroUser(username: "理工教学部", passwordHash: new Sha256Hash("1").toHex()) 
//                department1.save() 
//                def department2 = new ShiroUser(username: "文法教学部", passwordHash: new Sha256Hash("1").toHex()) 
//                department2.save() 
//               
//                //系部信息
//                def depart1 = new Department(departmentName:"开放教育运行学院")
//                depart1.addToUsers(department1)
//                depart1.save()
//               
//
//                
//                //系部角色
//                def role_department = new ShiroRole(name:"系部角色",roleDscp:"系部角色描述",roleType:1)
//                role_department.addToUsers(department1)
//                role_department.addToPermissions("Course")
//                role_department.addToPermissions("UserGroup")
//                role_department.save()
//                
//                //教师
//                def role_teacher = new ShiroRole(name:"教师",roleDscp:"教师描述",roleType:1)
//                role_teacher.addToPermissions("Course")
//                role_teacher.addToPermissions("Job")
//                role_teacher.addToPermissions("UserBaseinfo")
//                role_teacher.addToUsers(teacher1)
//                role_teacher.addToUsers(teacher2)
//                role_teacher.save()
//                
//                //参数设置
//                def config = new Config(name:"当前学期",configKey:"currentTerm",configValue: "2013年春季")
//                config.save()
//                
//               
//                
//                config = new Config(name:"分校预报截至日期",configKey:"branchForecast",configValue: "2012-10-07")
//                config.save()
//                
//                config = new Config(name:"分校正报截至日期",configKey:"branchOfficial",configValue: "2012-11-07")
//                config.save()
//                
//                config = new Config(name:"教师预报截至日期",configKey:"teacherForecast",configValue: "2012-12-17")
//                config.save()
//                
//                config = new Config(name:"教师正报截至日期",configKey:"teacherOfficial",configValue: "2012-12-27")
//                config.save()
//                
            
                break
                
            case "test":  
                break
           
                
        }
    }
    def destroy = {
    }
}
